﻿namespace FastCreateProject.Helpers
{
    /// <summary>
    /// 带错误编码的异常
    /// </summary>
    public class WithCodeException : Exception
    {
        public int Code { get; set; }

        public string? MessageDebug { get; set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="code"></param>
        /// <param name="message"></param>
        public WithCodeException(int code, string message) : base(message)
        {
            Code = code;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="code"></param>
        /// <param name="message"></param>
        /// <param name="messageDebug"></param>
        public WithCodeException(int code, string message, string messageDebug) : base(message)
        {
            Code = code;
            MessageDebug = messageDebug;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="code"></param>
        /// <param name="message"></param>
        public WithCodeException(ErrorCodeEnum code, string message) : base(message)
        {
            Code = (int)code;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="code"></param>
        /// <param name="message"></param>
        /// <param name="messageDebug"></param>
        public WithCodeException(ErrorCodeEnum code, string message, string messageDebug) : base(message)
        {
            Code = (int)code;
            MessageDebug = messageDebug;
        }
    }

    public enum ErrorCodeEnum
    {
        /// <summary>
        /// 没有错误
        /// </summary>
        None = 0,

        /// <summary>
        /// 未知错误
        /// </summary>
        UnknownError = 1,

        /// <summary>
        /// 参数无效
        /// </summary>
        InvalidArguments = 2,

        /// <summary>
        /// 签名校验失败
        /// </summary>
        FailedToCheckSign = 3,

        /// <summary>
        /// 序列化失败
        /// </summary>
        FailedToSerialize = 4,

        /// <summary>
        /// 反序列化失败
        /// </summary>
        FailedToDeserialize = 5,

        /// <summary>
        /// 请求已过期
        /// </summary>
        ExpiredRequest = 6,

        /// <summary>
        /// Session已过期
        /// </summary>
        ExpiredSession = 8,

        /// <summary>
        /// 调用频率超过限制
        /// </summary>
        OutOfFrequency = 9,

        /// <summary>
        /// 调用次数超过限制
        /// </summary>
        OutOfTimes = 10,

        /// <summary>
        /// 调用其他API超时
        /// </summary>
        OtherApiTimeout = 11,

        /// <summary>
        /// 未实现
        /// </summary>
        NotImplemented = 12,

        /// <summary>
        /// 没有权限
        /// </summary>
        NotAllowed = 13,

        /// <summary>
        /// 没有数据
        /// </summary>
        NoData = 14,

        /// <summary>
        /// 重定向
        /// </summary>
        Redirect = 15,

        /// <summary>
        /// 设置Session的重定向
        /// </summary>
        RedirectWithSession = 16,

        /// <summary>
        /// 设置Session
        /// </summary>
        SetSession = 17,

        /// <summary>
        /// 代码错误
        /// </summary>
        CodeError = 18,

        /// <summary>
        /// 调用其他API出错
        /// </summary>
        OtherApiError = 19
    }
}
